package com.xyazm.fulfill.mq.config;

import com.xyazm.common.enums.RocketMqTopicEnum;
import com.xyazm.fulfill.mq.consumer.TriggerOrderFulfillTopicListener;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.exception.MQClientException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class ConsumerConfig {

    @Autowired
    private RocketMQProperties rocketMQProperties;


    /**
     * 触发订单履约消息消费者
     * @author xuyou
     * 2022/8/15 0015 22:41
     * @param triggerOrderFulfillTopicListener
     * @return org.apache.rocketmq.client.consumer.DefaultMQPushConsumer
    */
    @Bean("triggerOrderFulfillConsumer")
    public DefaultMQPushConsumer triggerOrderFulfillConsumer(TriggerOrderFulfillTopicListener triggerOrderFulfillTopicListener)
            throws MQClientException {
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMqTopicEnum.TRIGGER_ORDER_FULFILL.getConsumerGroup());
        consumer.setNamesrvAddr(rocketMQProperties.getNameServer());
        consumer.subscribe(RocketMqTopicEnum.TRIGGER_ORDER_FULFILL.getTopic(), "*");
        consumer.registerMessageListener(triggerOrderFulfillTopicListener);
        consumer.start();
        return consumer;
    }



}
